<html>
<head><meta charset="utf-8"><title>running miri on capnp · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html">running miri on capnp</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="185780858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185780858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185780858">(Jan 16 2020 at 02:56)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I am impressed with how easy it easy to run miri on things these days. Bravo! And thanks for the suggestion.</p>



<a name="185781446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185781446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185781446">(Jan 16 2020 at 03:09)</a>:</h4>
<div class="codehilite"><pre><span></span>error: Miri evaluation error: no item granting read access to tag &lt;untagged&gt; found in borrow stack
    --&gt; /home/dwrensha/src/capnproto-rust/capnp/src/private/layout.rs:2863:18
     |
2863 |                 ((*b) &amp; (1u8 &lt;&lt; (boffset % BITS_PER_BYTE as u32) as usize)) != 0
     |                  ^^^^ Miri evaluation error: no item granting read access to tag &lt;untagged&gt; found in borrow stack
</pre></div>



<a name="185781451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185781451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185781451">(Jan 16 2020 at 03:10)</a>:</h4>
<p>oof. I'm not sure what that means.</p>



<a name="185788724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185788724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185788724">(Jan 16 2020 at 06:10)</a>:</h4>
<p>Oh no, an <code>untagged</code>. Not sure how to debug these</p>



<a name="185788783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185788783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185788783">(Jan 16 2020 at 06:12)</a>:</h4>
<p>Is <code>b</code> a raw pointer by any chance?</p>



<a name="185788800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185788800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185788800">(Jan 16 2020 at 06:13)</a>:</h4>
<p>Often this error means that after you created <code>b</code> , you wrote via the original reference that you got <code>b</code> from</p>



<a name="185796295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185796295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185796295">(Jan 16 2020 at 09:03)</a>:</h4>
<p>it also often means that you used a raw pointer outside of its "range of validity"</p>



<a name="185796350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185796350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185796350">(Jan 16 2020 at 09:04)</a>:</h4>
<p>like, maybe you did <code>&amp;x[0] as *const _</code> and then <code>offset</code> that pointer -- which is illegal, only <code>x[0]</code> may be accessed by raw ptrs</p>



<a name="185796355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185796355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185796355">(Jan 16 2020 at 09:04)</a>:</h4>
<p>if you want to access the entire thing, call <code>x.as_ptr()</code></p>



<a name="185808881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185808881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185808881">(Jan 16 2020 at 12:13)</a>:</h4>
<p>Yep, that was it! <a href="https://github.com/capnproto/capnproto-rust/commit/72480efb3514d32278bd2502a7b90b22a34d12b8" target="_blank" title="https://github.com/capnproto/capnproto-rust/commit/72480efb3514d32278bd2502a7b90b22a34d12b8">https://github.com/capnproto/capnproto-rust/commit/72480efb3514d32278bd2502a7b90b22a34d12b8</a></p>



<a name="185808888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185808888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185808888">(Jan 16 2020 at 12:13)</a>:</h4>
<p>why is <code>&amp;x[0] as *const _</code> illegal?</p>



<a name="185810330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810330">(Jan 16 2020 at 12:33)</a>:</h4>
<p><span class="user-mention" data-user-id="258831">@David Renshaw</span> the issue where we track that is <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/134" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/134">https://github.com/rust-lang/unsafe-code-guidelines/issues/134</a>. the wider context is <a href="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md">https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md</a> and the blog posts and papers it links.</p>



<a name="185810400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810400">(Jan 16 2020 at 12:34)</a>:</h4>
<p>basically, we want the compiler to optimize based on assumptions like "<code>&amp;mut</code> pointers are unique", and to that effect we have to be very careful what we actually allow to be done with raw pointers</p>



<a name="185810455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810455">(Jan 16 2020 at 12:35)</a>:</h4>
<p>note that the cast itself is perfectly legal, as is accessing the element you casted, but going outside that range is not allowed by the current model. there might be other models that do allow this, but likely at the cost of significant extra complexity (so, making it harder to understand the model) and/or at the cost of optimization potential.</p>



<a name="185810467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810467">(Jan 16 2020 at 12:35)</a>:</h4>
<p><span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<a name="185810526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810526">(Jan 16 2020 at 12:36)</a>:</h4>
<p>when I saw choices like this while designing Stacked Borrows, I usually decided to opt for the <em>more restrictive</em> choice. it is much easier to relax such constraints later than to tighten them.</p>



<a name="185810550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810550">(Jan 16 2020 at 12:36)</a>:</h4>
<p>basically, I wanted to see how much I could get away with :P</p>



<a name="185810703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810703">(Jan 16 2020 at 12:39)</a>:</h4>
<p>I added this to the list in the issue... but the list is pretty incomplete, this is probably the stacked borrows issue that comes up most freuqently (alongside <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/133" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/133">https://github.com/rust-lang/unsafe-code-guidelines/issues/133</a>)</p>



<a name="185810774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810774">(Jan 16 2020 at 12:40)</a>:</h4>
<p>re: <a href="https://github.com/capnproto/capnproto-rust/commit/3ea257068e9f7b6f3968a4ddb4669ff54ad79175" target="_blank" title="https://github.com/capnproto/capnproto-rust/commit/3ea257068e9f7b6f3968a4ddb4669ff54ad79175">https://github.com/capnproto/capnproto-rust/commit/3ea257068e9f7b6f3968a4ddb4669ff54ad79175</a>, I wonder if there is a way to reduce the number of iterations or so? to get at least a tiny bit of fuzzing done with miri?</p>



<a name="185810787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810787">(Jan 16 2020 at 12:40)</a>:</h4>
<p>but yeah, I've had to disable such tests in other repos as well :/</p>



<a name="185810812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810812">(Jan 16 2020 at 12:41)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> I am impressed with how easy it easy to run miri on things these days. Bravo! And thanks for the suggestion.</p>
</blockquote>
<p>(totally forgot to reply) thanks, that is encouraging :)</p>



<a name="185810885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810885">(Jan 16 2020 at 12:42)</a>:</h4>
<p>I was bracing myself for needing to get some kind of xargo setup going. It was amazing to be able to <code>rustup component add</code> and have it just work.</p>



<a name="185810933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185810933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185810933">(Jan 16 2020 at 12:43)</a>:</h4>
<p>yeah I hacked that auto-setup during RustFest Rome and later wondered why I hadn't done it earlier :D</p>



<a name="185811017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185811017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185811017">(Jan 16 2020 at 12:45)</a>:</h4>
<p>it's still just as ugly under the hood as it used to be, but hidden better^^</p>



<a name="185811390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185811390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185811390">(Jan 16 2020 at 12:52)</a>:</h4>
<p>The other immediate thing that miri is finding is that I create (but never deference) pointers that are exactly one element beyond the end of an allocation. I can understand why miri want me to not do that (and I'll fix my code), but just for perspective: this is following a c++ pattern of using "1 past end of container" as the end iterator <code>container.end()</code>.</p>



<a name="185813334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185813334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185813334">(Jan 16 2020 at 13:18)</a>:</h4>
<p>one past the end of the container pointers are ok: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=9b6b532e5b20d76ed422f7a86580af07" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=9b6b532e5b20d76ed422f7a86580af07">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=9b6b532e5b20d76ed422f7a86580af07</a></p>



<a name="185840890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185840890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185840890">(Jan 16 2020 at 17:55)</a>:</h4>
<p><span class="user-mention" data-user-id="258831">@David Renshaw</span> by "pointer", do you mean "reference"? because references in Rust are a bit like references in C++ in that they must be dereferencable. the one-past-the-end thing is invalid for both. it is valid for raw pointers though.</p>



<a name="185873687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185873687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Renshaw <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185873687">(Jan 16 2020 at 23:33)</a>:</h4>
<p>Indeed, my code constructs such invalid references! I didn't realize it because it immediately casts them to raw pointers.</p>



<a name="185897089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/running%20miri%20on%20capnp/near/185897089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/running.20miri.20on.20capnp.html#185897089">(Jan 17 2020 at 08:43)</a>:</h4>
<p><span class="user-mention" data-user-id="258831">@David Renshaw</span> ah... you might be interested in <a href="https://github.com/rust-lang/rfcs/pull/2582" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2582">https://github.com/rust-lang/rfcs/pull/2582</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>